package com.summer.Sort;

import java.util.Arrays;

public class day4 {
    static void quickSort(int[] arr,int left,int right){
        int pivot = arr[(left+right) / 2];
        int l = left;
        int r = right;
        int temp = 0;
        while (l < r){
            while (arr[l] < pivot) l++;
            while (arr[r] > pivot) r--;
            //if (l >= r) break;
            temp = arr[l];
            arr[l] = arr[r];
            arr[r] = temp;
            if (arr[l] == pivot) r--;
            if (arr[r] == pivot) l++;
            System.out.println(Arrays.toString(arr));
        }
        if (l < right) quickSort(arr,l,right);
        if (r > left) quickSort(arr,left,r);
    }
    public static void main(String[] args) {
        int N = 8000000;
        int[] arr1 = new int[N];
        for (int i = 0; i < N ; i++) {
            arr1[i] = (int) (Math.random()*N);
        }
        int[] arr = new int[]{9,4,2,8,1,5,3,8,9,4,6,5,7};
        int startTime = (int) System.currentTimeMillis();
        quickSort(arr,0,arr.length-1);
        int endTime = (int) System.currentTimeMillis();
        System.out.println("运行时间:"+(endTime-startTime)/1000+"s");
        System.out.println(Arrays.toString(arr));
    }
}
